#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x&-x)
using namespace std;
const int N=1005;
int n,q,a[N][N],c[N][N];
inline void upd(int y,int x,int num){
	while(x<=n) c[y][x]+=num,x+=lowbit(x);
}
inline int qry(int y,int x){
	int res=0;
	while(x) res+=c[y][x],x-=lowbit(x);
	return res;
} 
signed main() {
	freopen("fire.in","r",stdin);
	freopen("fire.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	while(q--){
		int oop,dir,x,op,num,p,q;
		cin>>oop;
		if(oop==2){
			cin>>p>>q;
			int ans=0;
			for(int i=1;i<=p;i++) ans+=qry(i,q);
			cout<<ans<<'\n';
		}
		else{
			cin>>dir>>x>>op>>num;
			if(!dir){
				for(int i=1;i<=n;i++){
					int tlh=a[x][i];
					if(op==1) a[x][i]&=num;
					if(op==2) a[x][i]|=num;
					if(op==3) a[x][i]^=num;
					if(op==4) a[x][i]=(a[x][i]+num)%999999999; 
					upd(x,i,a[x][i]-tlh);
				}
			}
			else{
				for(int i=1;i<=n;i++){
					int tlh=a[i][x];
					if(op==1) a[i][x]&=num;
					if(op==2) a[i][x]|=num;
					if(op==3) a[i][x]^=num;
					if(op==4) a[i][x]=(a[i][x]+num)%999999999; 
					upd(i,x,a[i][x]-tlh);
				}
			}
		}
	}
	return 0;
}
